package com.cs.beneficios.common.util;

import com.cs.beneficios.common.ConnectionFactory;

import java.sql.Connection;
import java.sql.SQLException;

public class ControlExceptions {

    /**
     * Conexion a la base de datos.
     */
    private static Connection conn = null;
    //private static ConnectionFactory cf;
       
    public ControlExceptions(ConnectionFactory cf) {
        
    }
    
    public static void insertException(Exception e, ConnectionFactory cf){
       try{
           conn = cf.getConnection();
           StackTraceElement[] ste = e.getStackTrace();
           String strMensaje = "Trace:";
           for(int i = 0;i < ste.length;i++) 
              strMensaje += "\r" + ste[i].toString();
           
           String query = " INSERT INTO TCS_BEN_LOG "+
                          " (CODIGO, FECHA_ORIGEN, "+
                          " MENSAJE_ERROR, PILA_ERROR) "+
                          " VALUES(SCS_BEN_LOG.NextVal, to_date(sysdate,'dd/mm/rrrr hh:mi:ss'),?,?)";
           
           String strArray[] = {e.getMessage(),strMensaje};           
           int iRegInsert = cf.execSql(query, strArray, conn);
           conn.close();
       }catch(SQLException ex) {
		System.err.println("/******** TDSUB - cwsub");
		ex.printStackTrace();
		System.err.println("TDSSPE - cwsub ********/");
       }
    }
}
